package com.boot.task;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @author Chunsheng.Zhang
 * @date 2021/1/7 11:39
 * @description : TODO
 */
@Component
public class MyAsyncTask {

    @Async
    public void task1() throws InterruptedException {
        long start = System.currentTimeMillis();
        Thread.sleep(3000);
        long end = System.currentTimeMillis();
        System.out.println("任务一耗时："+ (end-start)+"毫秒");
    }


    /**
     *
     * 任务2，我们不添加注解，便于验证
     *
     * */
    public void task2() throws InterruptedException {
        long start = System.currentTimeMillis();
        Thread.sleep(2000);
        long end = System.currentTimeMillis();
        System.out.println("任务二耗时："+ (end-start)+"毫秒");
    }


    /**
     *
     *
     * 任务3，我们不添加注解，便于验证
     *
     * */
    public void task3() throws InterruptedException {
        long start = System.currentTimeMillis();
        Thread.sleep(3000);
        long end = System.currentTimeMillis();
        System.out.println("任务三耗时："+ (end-start)+"毫秒");
    }
}
